package com.cxp.controller;

import com.alibaba.fastjson.JSONObject;
import com.cxp.entity.Projects;
import com.cxp.service.ProjectsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.websocket.server.PathParam;
import java.util.List;

/**
 * Created by cunxp on 2018/5/24.
 */
@RestController
@RequestMapping("/project")
public class ProjectsController {

    @Resource(name = "projectsService")
    private ProjectsService projectsService;

    @GetMapping
    public String listAll(){
        JSONObject jso = new JSONObject();
        List<Projects> list = projectsService.listAll();
        if(list != null){
            jso.put("data",list);
            jso.put("status","success");
        }else {
            jso.put("status","failed");
        }
        return jso.toJSONString();
    }

    @GetMapping("/{id}")
    public String queryById(@PathParam("id") String id){
        JSONObject jso = new JSONObject();
        Projects find = projectsService.queryById(id);
        if(find != null){
            jso.put("data",find);
            jso.put("status","success");
        }else {
            jso.put("status","failed");
        }
        return jso.toJSONString();
    }
}
